home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / nihcl-30.lha / nihcl-3.0 / lib / Time.h < prev    next >
C/C++ Source or Header  |  1990-05-19  |  3KB  |  94 lines

  1. #ifndef    TIME_H
  2. #define    TIME_H
  3.  
  4. /*$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/Time.h,v 3.0 90/05/20 00:21:46 kgorlen Rel $*/
  5.  
  6. /* Time.h -- declarations for class Time
  7.  
  8.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  9.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  10.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  11.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  12.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  13.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  14.  
  15. Author:
  16.     K. E. Gorlen
  17.     Computer Systems Laboratory, DCRT
  18.     National Institutes of Health
  19.     Bethesda, MD 20892
  20.  
  21. $Log:    Time.h,v $
  22.  * Revision 3.0  90/05/20  00:21:46  kgorlen
  23.  * Release for 1st edition.
  24.  * 
  25. */
  26.  
  27. #include "Object.h"
  28.  
  29. class Date;
  30.  
  31. #ifndef NESTED_TYPES
  32. typedef unsigned short hourTy;
  33. typedef unsigned short minuteTy;
  34. typedef unsigned short secondTy;
  35. typedef unsigned long clockTy;
  36. #endif
  37.  
  38. class Time: public VIRTUAL Object {
  39.     DECLARE_MEMBERS(Time);
  40. public:            // type definitions
  41. #ifdef NESTED_TYPES
  42.     typedef unsigned short hourTy;
  43.     typedef unsigned short minuteTy;
  44.     typedef unsigned short secondTy;
  45.     typedef unsigned long clockTy;
  46. #endif
  47. private:
  48.     clockTy sec;            /* seconds since 1/1/1901 */
  49.     bool isDST() const;
  50.     Time localTime() const;
  51. private:        // static member functions
  52.     static Time localTime(const Date& date, hourTy h=0, minuteTy m=0, secondTy s=0);
  53.     static Time beginDST(unsigned year);
  54.     static Time endDST(unsigned year);
  55. protected:        // storer() functions for object I/O
  56.     virtual void storer(OIOofd&) const;
  57.     virtual void storer(OIOout&) const;
  58. public:
  59.     Time();                // current time 
  60.     Time(clockTy s)            { sec = s; }
  61.     Time(hourTy h, minuteTy m, secondTy s =0, bool dst =NO);
  62.     Time(const Date&, hourTy h =0, minuteTy m =0, secondTy s=0, bool dst =NO);
  63.     operator Date() const;
  64.     bool operator<(const Time& t) const    { return sec < t.sec; }
  65.     bool operator<=(const Time& t) const    { return sec <= t.sec; }
  66.     bool operator>(const Time& t) const    { return sec > t.sec; }
  67.     bool operator>=(const Time& t) const    { return sec >= t.sec; }
  68.     bool operator==(const Time& t) const    { return sec == t.sec; }
  69.     bool operator!=(const Time& t) const    { return sec != t.sec; }
  70.     friend Time operator+(const Time& t, long s)    { return Time(t.sec+s); }
  71.     friend Time operator+(long s, const Time& t)    { return Time(t.sec+s); }
  72.     long operator-(const Time& t) const    { return sec - t.sec; }
  73.     Time operator-(long s) const    { return Time(sec-s); }
  74.     void operator+=(long s)        { sec += s; }
  75.     void operator-=(long s)        { sec -= s; }
  76.     bool between(const Time& a, const Time& b) const;
  77.     hourTy hour() const;        // hour in local time 
  78.     hourTy hourGMT() const;        // hour in GMT 
  79.     minuteTy minute() const;    // minute in local time 
  80.     minuteTy minuteGMT() const;    // minute in GMT 
  81.     secondTy second() const;    // second in local time or GMT 
  82.     clockTy    seconds() const        { return sec; }
  83.     Time max(const Time&) const;
  84.     Time min(const Time&) const;
  85.     virtual int compare(const Object&) const;
  86.     virtual void deepenShallowCopy();    // {}
  87.     virtual unsigned hash() const;
  88.     virtual bool isEqual(const Object&) const;
  89.     virtual void printOn(ostream& strm =cout) const;
  90.     virtual const Class* species() const;
  91. };
  92.  
  93. #endif /* TIMEH */
  94.